package com.ulife.supplier.module.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.FormGroup;
import com.ulife.supplier.dao.SupplierDao;
import com.ulife.supplier.dao.dataobject.SupplierDo;

/**
 * 供应商列表
 * 
 * @author Administrator
 */
public class SupplierAction {

	private static final Logger log = LoggerFactory.getLogger(SupplierAction.class);

	@Autowired
	private SupplierDao supplierDao;

	public void doAddSupplier(@FormGroup("addsupplier") SupplierDo supplierDo, Context context, Navigator nav) {
		try {
			supplierDao.insertSupplier(supplierDo);
		} catch (Exception e) {
			log.error("insertSupplier error "+supplierDo,e);
		}
		nav.redirectTo("supplierLink").withTarget("supplierlist");
	}
	
	public void doDelSupplier(@FormGroup("delsupplier") SupplierDo supplierDo, Context context, Navigator nav) {
		try {
			supplierDao.deleteSupplier(supplierDo.getsId());
		} catch (Exception e) {
			log.error("deleteSupplier error "+supplierDo,e);
		}
		nav.redirectTo("supplierLink").withTarget("supplierlist");
	}
	
	public void doUpdateSupplier(@FormGroup("updatesupplier") SupplierDo supplierDo, Context context, Navigator nav) {
		try {
			supplierDao.updateSupplier(supplierDo);
		} catch (Exception e) {
			log.error("updateSupplier error "+supplierDo,e);
		}
		nav.redirectTo("supplierLink").withTarget("supplierlist");
	}
	
	public void doQuerySupplier(@FormGroup("querysupplier") SupplierDo supplierDo, Context context, Navigator nav) {
		try {
			List<SupplierDo> sList = supplierDao.querySupplier(supplierDo);
			context.put("supplierList", sList);
		} catch (Exception e) {
			log.error("updateSupplier error "+supplierDo,e);
		}
	}
}
